//package com.fifth.sso.aop;
//
//import com.alibaba.fastjson.JSON;
//import com.fifth.common.pojo.dto.CommonResult;
//import com.fifth.common.pojo.entity.OptionLog;
//import com.fifth.sso.pojo.vo.LoginVo;
//import com.fifth.sso.service.IOptionLogService;
//import com.fifth.sso.utils.WebUtils;
//import org.apache.catalina.User;
//import org.aspectj.lang.JoinPoint;
//import org.aspectj.lang.annotation.AfterReturning;
//import org.aspectj.lang.annotation.Aspect;
//import org.checkerframework.checker.units.qual.A;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.redis.core.StringRedisTemplate;
//import org.springframework.stereotype.Component;
//import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletRequestAttributes;
//
//import javax.servlet.http.HttpServletRequest;
//import java.util.Date;
//import java.util.Map;
//
//@Component
//@Aspect
//public class LoginLogAop {
//    @Autowired
//    private IOptionLogService iOptionLogService;
//    @Autowired
//    private StringRedisTemplate redisTemplate;
//
//    //returning 是方法返回的结果
//    @AfterReturning(value = "execution(* com.fifth.sso.controller.LoginController.login(..))", returning = "result")
//    public void LoginAfterReturn(JoinPoint joinPoint, CommonResult result) {
//
//        HttpServletRequest request = WebUtils.getRequest();
//        String token = request.getHeader("token");
//        Map map = JSON.parseObject(redisTemplate.opsForValue().get(token), Map.class);
//        Map user = (Map) map.get("user");
//
//        String ename = (String) user.get("ename");
//        //获取登录者ip
//        String ip = request.getRemoteAddr();
//
//
//        //把结果强转为CommonResult类
////        CommonResult commonResult = (CommonResult) result;
//        //状态 0成功 1失败
////        Integer status = -1;
////        if (commonResult.getCode() == 2000) {
////            status = 0;
////        } else {
////            status = 1;
////        }
//
//        //封装一个登录日志对象
//        OptionLog optionLog = new OptionLog(null, ename,result.getMsg(),result.getData().toString(),new Date(),ip);
//        System.out.println(optionLog);
////        iOptionLogService.save(optionLog);
//
//    }
//}
